<template>
<div>

    <el-table
      ref="multipleTable"
      :data="tableData3"
      tooltip-effect="dark"
      style="width: 100%"
      @selection-change="handleSelectionChange">
      <el-table-column
        type="selection"
        width="55">
      </el-table-column>
      <el-table-column
        label="清单号"
        width="120">
        <template slot-scope="scope">{{ scope.row.date }}</template>
      </el-table-column>
      <el-table-column
        label="合同编号"
        width="120">
        <template slot-scope="scope">{{ scope.row.date }}</template>
      </el-table-column>
      <el-table-column
        prop="name"
        label="供应商"
        width="120">
      </el-table-column>
      <el-table-column
        prop="address"
        label="本方签订单位"
        show-overflow-tooltip>
      </el-table-column>
    </el-table>
    <el-row style="width:100%;">
      <el-col :span="24">
        <el-button type="primary" @click="multipleSelectSubmit" icon="el-icon-share">批量提交</el-button>
      </el-col>
    </el-row>
</div>
</template>
<script>
  import {createOne, deleteOne, deletePost, getOne, rolesAll, updateOneNoId} from '@/api/common'
  import {disableBtn, df, $err, $suc, ERRS, SUCS} from '@/utils'

  export default {
    name: 'formComp',
    props: {
      excelImportShow:Boolean
    },
    mounted() {
      this.temp = this.temps
    },
    data: function () {
      return {
        dialogFormVisible: false,
        dialogStatus: '',
        temp: {},
        tableData3: [{
          num: '20160503',
          date: '2016-05-03',
          name: '供应商1',
          address: '芜湖海螺'
        }, {
          num: '20160503',
          date: '2016-05-02',
          name: '供应商1',
          address: '芜湖海螺'
        }, {
          num: '20160503',
          date: '2016-05-04',
          name: '供应商1',
          address: '芜湖海螺'
        }, {
          num: '20160503',
          date: '2016-05-01',
          name: '供应商1',
          address: '芜湖海螺'
        }, {
          num: '20160503',
          date: '2016-05-08',
          name: '供应商1',
          address: '芜湖海螺'
        }, {
          num: '20160503',
          date: '2016-05-06',
          name: '供应商1',
          address: '芜湖海螺'
        }, {
          num: '20160503',
          date: '2016-05-07',
          name: '合同1',
          address: '芜湖海螺'
        }],
        multipleSelection: [],
        showDialog:false,
      }
    },
    computed: {
      importShow(){
        return this.excelImportShow
      }
    },
    watch: {

    },
    methods: {

      //批量提交
      multipleSelectSubmit() {
        this.$emit('update:importShow', false)  //关窗口 ,没提交
        console.log(this.$parent)
        // this.$parent.doChildSelection(this.multipleSelection) //关窗口 ,没提交
        this.$parent.doChildSelection()
      },
      handleSelectionChange(val) {
        this.multipleSelection = val;
      },
      //过滤数字以外的字符
      filterNumber() {
        this.temp.codeNo = this.temp.codeNo.toString().replace(/[^\d]/g, '')
      },
      //搜索栏 添加子级
      handleCreate() {
        this.temp = {
          codeNo: "",
          explainText: "",
        };
        this.dialogStatus = 'create'
        this.dialogFormVisible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].clearValidate()
        })
      },
      //添加提交
      createData() {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            disableBtn('cfmbtm1');
            if (!this.temp.parentId) {
              delete this.temp.parentId;
            }
            delete this.temp.show;
            createOne('codeExplains', this.temp).then(res => {

              this.dialogFormVisible = false
              // console.log(res);
              if (res.data.code === 0) {
                this.allList(0)
                $suc('创建成功!')
                this.$parent.getList();
              } else {
                ERRS(res.data.message)
              }
            })

          }
        })
      },
      //详情修改
      handleUpdate(row) {
        // console.log(row)
        this.temp = {
          id: row.id,
          codeNo: row.codeNo,
          explainText: row.explainText,
          show: `${row.level}级 ${row.fullname} (${row.fullCodeNo})`
        };
        this.$emit('update:tData', row)
        if (row.parentCodeExplain) //有子级加
          this.temp.parentId = row.parentCodeExplain.id
        this.dialogStatus = 'update'
        this.dialogFormVisible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].clearValidate()
        })
      },
      //修改提交
      updateData() {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            disableBtn('cfmbtm2');
            if (!this.temp.parentId) {
              delete this.temp.parentId;
            }
            delete this.temp.show;
            updateOneNoId('codeExplains', this.temp).then(res => {
              this.dialogFormVisible = false
              // console.log(res);
              if (res.data.code === 0) {
                $suc('更新成功!')
                this.$parent.getList();
              } else {
                ERRS(res.data.message)
              }
            })
          }
        })
      },
    }
  }
</script>
